/* See LICENSE for copyright and terms of use */

import org.evtmng.*;
import org.evtmng.events.*;
import org.evtmng.timeline.*;
import org.evtmng.tween.*;

/**
 * @author Tay Ray Chuan
 */

class org.evtmng.tween.TweenManager {
	private static var g_instance:TweenManager;

	public static function instance():TweenManager {
		if (g_instance == null) {
			g_instance = new TweenManager();
		}
		return g_instance;
	}

	private static var INTERVAL:Number = 100;

	private var m_tl:Timeline;
	private var m_tlm:TimelineManager;
	private var m_bcaster:TweenListenerBroadcaster;

	private function TweenManager() {
		m_tl = new Timeline();
		m_tlm = new TimelineManager(m_tl);

		m_tlm.setTimeInterval(INTERVAL);

		m_bcaster = TweenListenerBroadcaster.instance();
	}

	public function timeline():Timeline {
		return m_tl;
	}

	public function timelineManager():TimelineManager {
		return m_tlm;
	}

	public function tweenObjectPropertyEaserBeginChangeStartEnd(
		object:Object, property:String,
		easer:Function,
		begin:Number, change:Number,
		start:Number, end:Number):TweenHolder {
		var t:TweenHolder = (new TweenHolder()).
			initWithObjectPropertyBeginChange(object, property, begin, change).
			initWithStartEnd(start, end);
		t.setEaser(easer);

		m_tl.addTween(t.tween());
		m_bcaster.addListenerForTween(t, t.tween());

		return t;
	}

	public function run():Void {
		m_tlm.run();
	}
}